/**
 * Created by ptt on 2016/5/27/0027.
 */
define(["../../gis/gis/loadMap.js"], function (map) {
    var map = map.map;

    function toggleLayer(mapUrl, title, content) {
    	if (!mapUrl) return;
        if(title=="道路基础路网")
        {
           if(szvector) {
               var qunames=new Array();
              var features= szvector.getSource().getFeatures();
               if (features.length > 0) {
                   for (var i = 0; i < features.length; i++) {
                       var quname=features[i].get("qucode");
                       if(qunames.indexOf(quname)<0) {
                           qunames.push(quname);
                           var centerpoint = ol.extent.getCenter(features[i].getGeometry().getExtent());
                           var popup = new ol.Overlay.Popup({insertFirst: false});
                           map.addOverlay(popup);
                           var srcurl = "http://localhost:8080/ssjc/taglib/roadbasicinfo!showByDistrict.action?fromParam=amount&type=101&district=" + quname + " frameborder='0' scrolling='no'";
                           popup.show(centerpoint, '<div><iframe src=' + srcurl + ' width="200" height="200"> <p>');
                       }
                   }

               }
               else {
                   map.removeOverlay(map.getOverlays());
               }
           }
        }
        else if(title=="规划分布")
        {

            var vectorSource = new ol.source.Vector({
                url:"",
                format: new ol.format.GeoJSON()
            });
            var vectorLayer = new ol.layer.Vector({
                source: vectorSource,
                style: new ol.style.Style({
                    stroke: new ol.style.Stroke({
                        color: 'red',
                        size: 1
                    })
                })
            });
            map.addLayer(vectorLayer);
        }
        else {
            if (!$("#map-map").data(mapUrl)) {
                var layer = new ol.layer.Tile({
                    source: new ol.source.TileArcGISRest({
                        url: mapUrl
                    })
                });
                map.addLayer(layer);
                $("#map-map").data(mapUrl, layer);
            } else {
                layer = $("#map-map").data(mapUrl);
                map.removeLayer(layer);
                $("#map-map").removeData(mapUrl);
            }
        }
        //设置地图中心点
        map.getView().setCenter(ol.proj.transform([114.034428, 22.535805], 'EPSG:4326', 'EPSG:900913'));
    }

});